Skip to content

fix: send/receive asset selection should handle unsupported assets (#3311) - #12526

Merged
kaladinlight merged 9 commits into
shapeshift:developfrom
joan-bisbal:fix/unsupported-asset-selection
Aug 5, 2026
Merged

fix: send/receive asset selection should handle unsupported assets (#3311)#12526
kaladinlight merged 9 commits into
shapeshift:developfrom
joan-bisbal:fix/unsupported-asset-selection

Conversation

@joan-bisbal

@joan-bisbal joan-bisbal commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Fixes #3311

When navigating within an asset view, opening the send/receive modal, and clicking back, the full list of all supported assets is displayed—including assets unsupported by the user's connected wallet.

This PR fixes the issue by ensuring that the fallback \portfolioAssetsSortedByBalance\ is properly filtered against \walletConnectedChainIds\ when \�llowWalletUnsupportedAssets\ is falsy (which is the case for Send/Receive modals).

Summary by CodeRabbit

  • Bug Fixes

    • Improved asset filtering in trade search to respect connected wallet networks and unsupported-asset settings.
    • Ensured popular and portfolio asset results follow consistent filtering rules.
    • Preserved access to assets when no wallet is connected or unsupported assets are explicitly allowed.
  • Tests

    • Added coverage for wallet connection states, unsupported-asset settings, and optional asset filters.

@joan-bisbal
joan-bisbal requested a review from a team as a code owner August 4, 2026 22:28
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 12f9f1e4-e26a-405b-a5b3-e3d55a3e7d6d

📥 Commits

Reviewing files that changed from the base of the PR and between fa6f425 and 172c8dd.

📒 Files selected for processing (3)
  • src/components/TradeAssetSearch/TradeAssetSearch.tsx
  • src/components/TradeAssetSearch/helpers/filterAssetsForWallet.test.ts
  • src/components/TradeAssetSearch/helpers/filterAssetsForWallet.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/TradeAssetSearch/TradeAssetSearch.tsx

📝 Walkthrough

Walkthrough

The change adds a shared wallet-aware asset filter. Popular and portfolio asset searches use it with asset predicates, wallet-chain restrictions, and updated memoization dependencies. Tests cover connected and disconnected wallets, unsupported-asset settings, and predicates.

Changes

Asset search filtering

Layer / File(s) Summary
Define and validate shared filtering
src/components/TradeAssetSearch/helpers/filterAssetsForWallet.ts, src/components/TradeAssetSearch/helpers/filterAssetsForWallet.test.ts
The helper applies optional asset predicates and conditional wallet-chain restrictions. Tests cover wallet connection and unsupported-asset settings.
Integrate filtering into asset search
src/components/TradeAssetSearch/TradeAssetSearch.tsx
Popular and portfolio asset filtering uses the shared helper. Memoization dependencies include wallet state, supported chains, and unsupported-asset settings.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: 0xapotheosis, kaladinlight

Poem

A rabbit checks each asset’s chain,
With wallet rules kept clear and plain.
Popular, portfolio lists align,
Predicates guide the search in time.
Unsupported paths stay in view—
When settings say that they may do.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the fix for unsupported asset selection in Send/Receive flows.
Linked Issues check ✅ Passed The changes filter Send/Receive assets by connected-wallet chain support and cover the required fallback behavior in tests [#3311].
Out of Scope Changes check ✅ Passed The helper, popular-asset filtering, portfolio filtering, and regression tests directly support the linked issue objectives [#3311].
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
src/components/TradeAssetSearch/TradeAssetSearch.tsx (2)

218-222: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add regression coverage for wallet-supported portfolio filtering.

Please add or verify tests for these cases:

  • A connected wallet with allowWalletUnsupportedAssets === false excludes unsupported chains.
  • A connected wallet with allowWalletUnsupportedAssets === true retains those assets.
  • No connected wallet does not filter by walletConnectedChainIds.

Use assets with both supported and unsupported asset.chainId values. This directly covers the back-navigation regression.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/TradeAssetSearch/TradeAssetSearch.tsx` around lines 218 - 222,
Add regression tests for the portfolio filtering logic in TradeAssetSearch,
covering supported and unsupported asset.chainId values. Verify that a connected
wallet excludes unsupported chains when allowWalletUnsupportedAssets is false,
retains them when true, and that no connected wallet leaves all assets
unfiltered by walletConnectedChainIds.

215-215: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add explicit types to the new filter callbacks.

The callbacks at Line 215 and Line 220 rely on contextual inference. Add (asset: Asset): boolean to both callbacks.

As per coding guidelines, TypeScript function parameters and return values must be explicit.

Proposed change
-      asset => assetFilterPredicate?.(asset.assetId) ?? true,
+      (asset: Asset): boolean => assetFilterPredicate?.(asset.assetId) ?? true,
...
-        asset => walletConnectedChainIds.includes(asset.chainId),
+        (asset: Asset): boolean => walletConnectedChainIds.includes(asset.chainId),

Run pnpm run lint --fix and pnpm run type-check after the change.

Also applies to: 220-220

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/TradeAssetSearch/TradeAssetSearch.tsx` at line 215, Update
both filter callbacks in the TradeAssetSearch filtering logic (the callbacks at
the referenced lines) to explicitly declare the parameter as Asset and the
return type as boolean, including the callback using assetFilterPredicate?.
Preserve their existing filtering behavior, then run pnpm run lint --fix and
pnpm run type-check.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/components/TradeAssetSearch/TradeAssetSearch.tsx`:
- Around line 218-222: Add regression tests for the portfolio filtering logic in
TradeAssetSearch, covering supported and unsupported asset.chainId values.
Verify that a connected wallet excludes unsupported chains when
allowWalletUnsupportedAssets is false, retains them when true, and that no
connected wallet leaves all assets unfiltered by walletConnectedChainIds.
- Line 215: Update both filter callbacks in the TradeAssetSearch filtering logic
(the callbacks at the referenced lines) to explicitly declare the parameter as
Asset and the return type as boolean, including the callback using
assetFilterPredicate?. Preserve their existing filtering behavior, then run pnpm
run lint --fix and pnpm run type-check.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ecde0be5-9c79-4ece-88e6-919cd8a87601

📥 Commits

Reviewing files that changed from the base of the PR and between 90f7ef1 and fd043c8.

📒 Files selected for processing (1)
  • src/components/TradeAssetSearch/TradeAssetSearch.tsx

joan-bisbal and others added 6 commits August 5, 2026 00:39
Same predicate-then-chain-filter semantics, now shared with the
portfolio list via the helper introduced in this PR.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The helper applies the caller predicate plus wallet-support policy, not
generic chain filtering, and the sibling hooks/ dir uses flat files.
Also drop redundant parameter/return annotations per local idiom.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (4)
src/components/TradeAssetSearch/helpers/filterAssetsByChain/filterAssetsByChain.test.ts (4)

9-19: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Rename immutable test fixtures to UPPER_SNAKE_CASE.

Rename supportedAsset, unsupportedAsset, and assets to descriptive constant names such as SUPPORTED_ASSET, UNSUPPORTED_ASSET, and TEST_ASSETS.

As per coding guidelines, "Use UPPER_SNAKE_CASE for constants and configuration values with descriptive names."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@src/components/TradeAssetSearch/helpers/filterAssetsByChain/filterAssetsByChain.test.ts`
around lines 9 - 19, Rename the immutable test fixtures supportedAsset,
unsupportedAsset, and assets to descriptive UPPER_SNAKE_CASE constants such as
SUPPORTED_ASSET, UNSUPPORTED_ASSET, and TEST_ASSETS, and update all references
in the test accordingly.

Source: Coding guidelines


9-17: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Remove the unchecked Asset assertions.

Lines 12 and 17 claim that incomplete objects are Asset values. This hides missing required fields from type checking.

Make filterAssetsByChain generic over Pick<Asset, 'assetId' | 'chainId'>, preserve the generic type in its return value, and declare these fixtures with that explicit type. Do not cast them to Asset.

After the change, run pnpm run lint --fix and pnpm run type-check.

As per coding guidelines, "NEVER use type assertions without proper validation in TypeScript."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@src/components/TradeAssetSearch/helpers/filterAssetsByChain/filterAssetsByChain.test.ts`
around lines 9 - 17, Update filterAssetsByChain to be generic over Pick<Asset,
'assetId' | 'chainId'> and preserve that generic type in its return value. In
the test fixtures, explicitly type supportedAsset and unsupportedAsset as the
required Pick shape and remove the unchecked Asset assertions; then run pnpm run
lint --fix and pnpm run type-check.

Source: Coding guidelines


54-61: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Declare the predicate parameter and return types.

Add an explicit AssetId type for assetId and an explicit boolean return type for the callback.

-      assetFilterPredicate: assetId => assetId === ethAssetId,
+      assetFilterPredicate: (assetId: AssetId): boolean => assetId === ethAssetId,

As per coding guidelines, "ALWAYS use explicit types for function parameters and return values in TypeScript."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@src/components/TradeAssetSearch/helpers/filterAssetsByChain/filterAssetsByChain.test.ts`
around lines 54 - 61, Update the assetFilterPredicate callback in the test to
explicitly type its assetId parameter as AssetId and its return value as
boolean, reusing the existing AssetId type import or symbol.

Source: Coding guidelines


21-30: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Test the omitted optional flag.

allowWalletUnsupportedAssets is optional. When it is omitted, !allowWalletUnsupportedAssets enables wallet-chain filtering. Add a case that omits this property and expects only SUPPORTED_ASSET.

Proposed test
+  it('excludes unsupported chains when allowWalletUnsupportedAssets is omitted', () => {
+    const result = filterAssetsByChain({
+      assets: TEST_ASSETS,
+      hasWallet: true,
+      walletConnectedChainIds: [KnownChainIds.EthereumMainnet],
+    })
+
+    expect(result).toEqual([SUPPORTED_ASSET])
+  })
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@src/components/TradeAssetSearch/helpers/filterAssetsByChain/filterAssetsByChain.test.ts`
around lines 21 - 30, The existing test only covers allowWalletUnsupportedAssets
set to false; add a separate case for filterAssetsByChain that omits this
optional property while keeping the wallet connected and walletConnectedChainIds
restricted to EthereumMainnet, and assert the result contains only
supportedAsset.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@src/components/TradeAssetSearch/helpers/filterAssetsByChain/filterAssetsByChain.test.ts`:
- Around line 9-19: Rename the immutable test fixtures supportedAsset,
unsupportedAsset, and assets to descriptive UPPER_SNAKE_CASE constants such as
SUPPORTED_ASSET, UNSUPPORTED_ASSET, and TEST_ASSETS, and update all references
in the test accordingly.
- Around line 9-17: Update filterAssetsByChain to be generic over Pick<Asset,
'assetId' | 'chainId'> and preserve that generic type in its return value. In
the test fixtures, explicitly type supportedAsset and unsupportedAsset as the
required Pick shape and remove the unchecked Asset assertions; then run pnpm run
lint --fix and pnpm run type-check.
- Around line 54-61: Update the assetFilterPredicate callback in the test to
explicitly type its assetId parameter as AssetId and its return value as
boolean, reusing the existing AssetId type import or symbol.
- Around line 21-30: The existing test only covers allowWalletUnsupportedAssets
set to false; add a separate case for filterAssetsByChain that omits this
optional property while keeping the wallet connected and walletConnectedChainIds
restricted to EthereumMainnet, and assert the result contains only
supportedAsset.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a26d71ba-6707-437c-b4c5-dbf5aafc9f31

📥 Commits

Reviewing files that changed from the base of the PR and between 0230ab5 and fa6f425.

📒 Files selected for processing (3)
  • src/components/TradeAssetSearch/TradeAssetSearch.tsx
  • src/components/TradeAssetSearch/helpers/filterAssetsByChain/filterAssetsByChain.test.ts
  • src/components/TradeAssetSearch/helpers/filterAssetsByChain/filterAssetsByChain.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/TradeAssetSearch/TradeAssetSearch.tsx

@kaladinlight

Copy link
Copy Markdown
Member

Thanks for this fix — good catch, and the regression tests are appreciated. Verified the root cause: with a zero-balance (or freshly connected) wallet, the portfolio list falls back to the full asset universe (selectPrimaryAssetsByChainId), which is exactly how unsupported assets leaked into send/receive. Your filter closes it, and the buy-side flow (allowWalletUnsupportedAssets) is unaffected — confirmed manually.

Heads-up that we pushed a few small commits onto your branch while validating, so pull before making further changes:

  • abce79cb1b — routed the popularAssets memo through your helper too, which retires the old TODO there; one policy, one function, both lists
  • fa6f425dfb — two mechanical lint fixes CI would have flagged (import sort, arrow parens — pnpm run lint --fix catches these locally)
  • 6b7a35f8c0 — renamed the helper to filterAssetsForWallet (it applies wallet-support policy, not generic chain filtering) and flattened the folder to match the sibling hooks/ layout

Nothing behavioral changed in your fix itself. Should be good to merge once CI runs.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@kaladinlight
kaladinlight enabled auto-merge (squash) August 5, 2026 18:21
@kaladinlight kaladinlight changed the title fix: Send/receive asset selection should handle unsupported assets (#3311) fix: send/receive asset selection should handle unsupported assets (#3311) Aug 5, 2026
@kaladinlight
kaladinlight merged commit 2f6456a into shapeshift:develop Aug 5, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Send/receive asset selection should handle unsupported assets

2 participants